package com.roast.pages;

import java.util.ArrayList;
import java.util.List;
import com.roast.domain.Event;
import com.roast.domain.UserData;
import com.roast.services.my.MyServicesFacade;
import com.roast.util.EventSSO;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionAttribute;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

public class UserEvents {

    @Inject
    MyServicesFacade myServices;

    @SessionAttribute
    UserData userSA;

    @SessionState
    private EventSSO eventSSO;

    @Property
    Event event;

    @SessionAttribute
    boolean loginSA;

    public List<Event> getEvents() {
        Event event = new Event();
        event.setMaster(userSA);

        ArrayList<Event> eventList = new ArrayList<>();

        eventList.add(event);

        int signal = myServices.getUserEvents(eventList);
        if (signal == 12000) {
            return eventList;
        }
        return null;
    }

    @OnEvent(component = "eventLink")
    Object onShowEvent(long id) {
        Event eventShow = new Event();
        eventShow.setEventID(id);
        int signal = myServices.getEvent(eventShow);

        if (signal == 10600) {
            eventSSO.setEvent(eventShow);
            return UserEvent.class;
        }
        return UserEvents.class;
    }

    Object onActivate() {
        if (!loginSA) {
            return Index.class;
        } else {
            return null;
        }
    }
}
